<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <!--<div class="layui-inline">
                            <label class="layui-form-label">设备类型</label>
                            <div class="layui-input-inline">
                                <select id="ename" name="tid"></select>
                            </div>
                        </div>-->
                        <div class="layui-inline">
                            <label class="layui-form-label">申请时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="searchTime" name="searchTime">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">设备编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="eid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">申请编号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="repId" name="repId" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">申请状态</label>
                            <div class="layui-input-inline">
                                <input type="text" id="state" name="state" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <!--<script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>-->

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            {{# if(d.state == '未受理'){ }}
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="accept">接受</a>
            {{# } }}
            {{# if(d.state == '已接受'){ }}
            <a class="layui-btn layui-btn-xs" lay-event="finish">完成</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="scrap">报废申请</a>
            {{# } }}
        </script>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'laydate'], function () {
        //使用jquery
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        laydate.render({
            elem: '#searchTime' //指定元素
            , range: true
        });
        table.render({
            elem: '#currentTableId',
            url: '/application/equipment/show',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'repId', title: '申请编号'},
                {field: 'eid', title: '设备编号'},
                {field: 'reason', title: '维修原因'},
                {
                    field: 'creatTime',
                    title: '申请时间',
                    templet: '<div>{{layui.util.toDateString(d.creatTime,"yyyy-MM-dd")}}</div>'
                },
                {field: 'state', title: '状态'},
                {title: '操作', toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [5, 10, 15, 20],
            limit: 10,
            page: true,
            skin: 'line'
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            console.log(data);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    repId: data.field.repId,
                    searchTime: data.field.searchTime,
                    eid: data.field.eid,
                    state: data.field.state,
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'accept') {
                console.log(obj.data);
                $.post("/repair/accept", obj.data, function (data) {
                    location.reload();
                });

            } else if (obj.event === 'finish') {
                $.post("/repair/finish", obj.data, function (data) {
                    location.reload();
                });
            } else if (obj.event === 'scrap') {
                $.post("/repair/scrap", obj.data, function (data) {
                    location.reload();
                });
            }
            return false;
        });


    });
</script>

</body>
</html>